package me.work.pay.jsyl.app.utils;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

import me.work.pay.jsyl.R;

/**
 * description ：
 * author : Brovee
 * email : 8413951@qq.com
 * date : 2020/10/19 15:17
 */
public class NumberPlayer {
    private static volatile NumberPlayer instance;
    int[] sounds = new int[11];
    private static  SoundPool mSoundPool;
    private NumberPlayer() {
        if (mSoundPool == null)
            mSoundPool = new SoundPool(27, AudioManager.STREAM_MUSIC, 100);
    }

    public void init(Context mContext) {
        sounds[0] = mSoundPool.load(mContext,R.raw.a0,1);
        sounds[1] = mSoundPool.load(mContext,R.raw.a1,1);
        sounds[2] = mSoundPool.load(mContext,R.raw.a2,1);
        sounds[3] = mSoundPool.load(mContext,R.raw.a3,1);
        sounds[4] = mSoundPool.load(mContext, R.raw.a4,1);
        sounds[5] = mSoundPool.load(mContext,R.raw.a5,1);
        sounds[6] = mSoundPool.load(mContext,R.raw.a6,1);
        sounds[7] = mSoundPool.load(mContext,R.raw.a7,1);
        sounds[8] = mSoundPool.load(mContext,R.raw.a8,1);
        sounds[9] = mSoundPool.load(mContext,R.raw.a9,1);
        sounds[10] = mSoundPool.load(mContext, R.raw.dian,1);//点
    }

    public void play(int position){
        mSoundPool.play(sounds[position], 1.0f, 1.0f, 0, 0, 1.0f);

    }
    public static NumberPlayer getInstance() {
        if (instance == null) {
            synchronized (NumberPlayer.class) {
                if (instance == null) {
                    instance = new NumberPlayer();
                }
            }
        }
        return instance;
    }

    public  SoundPool getSoundPool() {
        return mSoundPool;
    }
}
